package pers.gxm.abstractfactory.factory;

import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;

public abstract class Page {
    protected String title;
    protected String author;
    protected ArrayList<Item> content = new ArrayList<>();
    public Page(String title,String author){
        this.title = title;
        this.author = author;
    }
    public void add(Item item){
//        item.increaseElementLevel();
        content.add(item);
    }
    public abstract String makeHTML();
    public void output(){
        String filename = title + ".html";
        try(FileWriter fileWriter = new FileWriter(filename)){
            fileWriter.write(this.makeHTML());
            fileWriter.close();
            System.out.println(filename + "编写完成。");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
